package com.demo.security.service;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
 * AuthorityService
 *
 * @author chenyang
 * @date 2020/10/10
 */
@Service("auth")
public class AuthorityService {

    public boolean hasAuthority(String auth) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println(authentication);
        System.out.println(authentication.getPrincipal());
        System.out.println(authentication.getCredentials());
        System.out.println(authentication.isAuthenticated());
        // 查询数据库
        if (auth.equalsIgnoreCase("sys:user:admin")) {
            return true;
        }
        return false;
    }
}
